using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Quanly_dethi.Class;

namespace Quanly_dethi
{
    public partial class frmThitracnghiem : Form
    {
        DataTable MangCauHoi = new DataTable();
        int vtcauhoihientai = -1;

        private csB_Dokho dk;
        private csB_Quyen td;
        private csB_Thisinh us;
        private csB_Cauhoi ch;
        private csB_DapanCH da;
        private string tenmay = bienketnoi.tenmay;
        private string taikhoan = bienketnoi.taikhoan;
        private string matkhau = bienketnoi.matkhau;
        private string tencsdl = bienketnoi.tencsdl;
        int minute = 10; int second = 00;
        int tongcauhoi = 0; int macauhoi = 0;
        private int trinhdo = bienketnoi.cbtk;
        private int dokho = bienketnoi.cbdk;
        float diem = 0;
        public frmThitracnghiem()
        {
            dk = new csB_Dokho(tenmay, taikhoan, matkhau, tencsdl);
            us = new csB_Thisinh(tenmay, taikhoan, matkhau, tencsdl);
            td = new csB_Quyen(tenmay, taikhoan, matkhau, tencsdl);
            ch = new csB_Cauhoi(tenmay, taikhoan, matkhau, tencsdl);
            da = new csB_DapanCH(tenmay, taikhoan, matkhau, tencsdl);
            InitializeComponent();
        }

        private void loadch()
        {
            if (vtcauhoihientai < 19)
            {


                vtcauhoihientai++;
                //tongcauhoi += 1;
                //lb_stt.Text = tongcauhoi.ToString();
                //DataTable k = ch.Sellect_Mch_ngaunhien(dokho,trinhdo);
                string s = ""; string da1 = ""; string da2 = ""; string da3 = ""; string da4 = "";
                ////for (int i = 0; i < k.Rows.Count; i++)
                ////{
                //    lb_cauhoi.Text = k.Rows[i][1].ToString();
                //    macauhoi = int.Parse(k.Rows[i][0].ToString());

                ////}

                lb_cauhoi.Text = MangCauHoi.Rows[vtcauhoihientai][1].ToString();
                macauhoi = int.Parse(MangCauHoi.Rows[vtcauhoihientai][0].ToString());
                DataTable d = ch.getdapandung(macauhoi);
                for (int j = 0; j < d.Rows.Count; j++)
                {
                    lb_da_1.Text = d.Rows[0][0].ToString();
                    lb_da_2.Text = d.Rows[1][0].ToString();
                    lb_da_3.Text = d.Rows[2][0].ToString();
                    lb_da_4.Text = d.Rows[3][0].ToString();
                }
            }
        }

        private void frmThitracnghiem_Load(object sender, EventArgs e)
        {
            loadch();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (second < 1)
            {
                second = 59;
                if (minute == 0)
                {
                    minute = 59;
                }
                else
                {
                    minute -= 1;
                }
            }
            else
            {
                second -= 1;
            }
            lb_min.Text = minute.ToString();
            lb_seconds.Text = second.ToString();
            if (second == 0 && minute == 0)
            {
                lb_min.Text = "00";
                lb_seconds.Text = "00";
                timer1.Enabled = false;
            }
        }
        void LayMangCauHoi()
        {
            MangCauHoi = ch.Sellect_Mch_ngaunhien(dokho, trinhdo);
        }
        void LoadCauHoiTruocDo()
        {
            if (vtcauhoihientai > 0)
            {


                vtcauhoihientai--;
                //tongcauhoi += 1;
                //lb_stt.Text = tongcauhoi.ToString();
                //DataTable k = ch.Sellect_Mch_ngaunhien(dokho,trinhdo);
                string s = ""; string da1 = ""; string da2 = ""; string da3 = ""; string da4 = "";
                ////for (int i = 0; i < k.Rows.Count; i++)
                ////{
                //    lb_cauhoi.Text = k.Rows[i][1].ToString();
                //    macauhoi = int.Parse(k.Rows[i][0].ToString());

                ////}

                lb_cauhoi.Text = MangCauHoi.Rows[vtcauhoihientai][1].ToString();
                macauhoi = int.Parse(MangCauHoi.Rows[vtcauhoihientai][0].ToString());
                DataTable d = ch.getdapandung(macauhoi);
                for (int j = 0; j < d.Rows.Count; j++)
                {
                    lb_da_1.Text = d.Rows[0][0].ToString();
                    lb_da_2.Text = d.Rows[1][0].ToString();
                    lb_da_3.Text = d.Rows[2][0].ToString();
                    lb_da_4.Text = d.Rows[3][0].ToString();
                }
            }
            
        
    }

        private void bt_next_Click(object sender, EventArgs e)
        {
        
        }

        private void bt_chtruocdo_Click(object sender, EventArgs e)
        {
             LoadCauHoiTruocDo();
        }
    }
}